package lesson13;

import javax.swing.*;
import java.awt.event.*;

public class Test03 extends JFrame implements ActionListener {
    private JButton button;
    private JButton cancelBtn;
    private JTextField countTextField;
    public Test03(){
        this.setLayout(null);

        button = new JButton("ok");
        button.setBounds(0,0,150,30);
        button.addActionListener(new ActionListener(){

            @Override
            public void actionPerformed(ActionEvent e) {

            }
        });
        button.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                System.out.println("进入：" + e.getX() + " " + e.getY());
            }
            @Override
            public void mouseExited(MouseEvent e) {
                System.out.println("退出：" + e.getX() + " " + e.getY());
            }
        });
        this.add(button);

        cancelBtn = new JButton("cancel");
        cancelBtn.setBounds(150,0,150,30);
        cancelBtn.addActionListener(this);
        this.add(cancelBtn);

        countTextField = new JTextField("0");
        countTextField.setBounds(0,30,300,30);
        this.add(countTextField);

        this.setSize(800,600);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }
    public static void main(String[] args) {
        new Test03();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == button){
            countTextField.setText(Integer.parseInt(countTextField.getText()) + 1 + "");
        }else if(e.getSource() == cancelBtn){
            countTextField.setText(Integer.parseInt(countTextField.getText()) - 1 + "");
        }
//        if("ok".equals(e.getActionCommand())){
//            System.out.println("ok");
//        }else if("cancel".equals(e.getActionCommand())){
//            System.out.println("cancel");
//        }

    }



}
